import java.util.PriorityQueue;

public class Solution2 {

}

class KthLargest {

    PriorityQueue<Integer> heap;
    int k;
    public KthLargest(int _k, int[] nums) {
        heap = new PriorityQueue<>((a,b) -> a - b);
        k = _k;
        for(int x : nums) {
            heap.offer(x);
            if(heap.size() > k) {
                heap.poll();
            }
        }
    }

    public int add(int val) {
        heap.offer(val);
        if(heap.size() > k) {
            heap.poll();
        }
        return heap.peek();
    }
}
